﻿using System;
using SaaSKit.Taskr.Service;
using Apprenda.SaaSGrid;
using System.Collections.Generic;

namespace root.Models
{
    public class Task
    {

        public Guid Id { get; set; }
        public string Summary { get; set; }
        public string Description { get; set; }
        public string Status { get; set; }
        public DateTime? DueDate { get; set; }
        public DateTime CreatedDate { get; set; }
        public DateTime? CompletedDate { get; set; }
        public Guid? AssigneeId { get; set; }
        public ITenantUser Assignee { get; set; }
        public IList<ActivityDTO> ActivityHistory { get; set; }

        public void MapFrom(TaskDTO dto)
        {

            if (null != dto && !(dto is TaskDTO))
            {
                throw new ArgumentException();
            }

            Id = dto.Id;
            Summary = dto.Summary;
            Description = dto.Description;
            DueDate = dto.DueDate;
            CreatedDate = dto.CreatedDate;
            CompletedDate = dto.CompletedDate;
            AssigneeId = dto.AssigneeId;
            Status = dto.Status;
            ActivityHistory = dto.ActivityHistory;
            
            if (AssigneeId.HasValue)
            {
                if (AssigneeId == UserContext.Instance.CurrentUser.Id)
                {
                    Assignee = UserContext.Instance.CurrentUser;
                }
                else
                {
                    Assignee = TenantContext.Current.GetUser(AssigneeId.Value);
                }
            }

        }

    }
}